<template>
    <div>
        <!--卡片-->
        <el-card class="box-card">
            <!--定义面包屑-->
            <el-breadcrumb separator=">">
                <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>客户管理</el-breadcrumb-item>
                <el-breadcrumb-item>优惠券记录</el-breadcrumb-item>
            </el-breadcrumb>
            <el-divider></el-divider>
            <!--表单的搜索框
                 :model="双向绑定表单的数据"
            -->
            <el-form :inline="true" :model="couponRecordFormData"  class="demo-form-inline">
                <el-form-item >
                    <el-input v-model="couponRecordFormData.couponName" placeholder="请输入优惠券名称"></el-input>
                </el-form-item>
                <el-form-item >
                    <el-input v-model="couponRecordFormData.clientName" placeholder="请输入客户名称"></el-input>
                </el-form-item>
                <el-form-item >
                    <el-select v-model="couponRecordFormData.useStatus" clearable placeholder="请选择使用状态">
                        <el-option
                                v-for="item in options"
                                :key="item.value"
                                :label="item.lable"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item >
                    <el-input v-model="couponRecordFormData.orderNumber" placeholder="请输入订单编号"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="getAllCouponRecord()">查询</el-button>
                </el-form-item>
            </el-form>

            <!--数据表格-->
            <template>
                <el-table
                        :data="tableData"
                        :border="true"
                        stripe
                        style="width: 100%">
                    <el-table-column
                            prop="id"
                            label="积分记录ID">
                    </el-table-column>
                    <el-table-column
                            prop="clientCoupon.couponName"
                            label="优惠券名称">
                    </el-table-column>
                    <el-table-column
                            prop="clientUser.username"
                            label="客户名称">
                    </el-table-column>
                    <el-table-column
                            prop="claimStatus"
                            label="领取状态">
                        <template slot-scope="scope">
                            <span v-if="scope.row.claimStatus==0">未领取</span>
                            <span v-if="scope.row.claimStatus==1">已领取</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                            prop="receiveTime"
                            label="领取时间">
                    </el-table-column>
                    <el-table-column
                            prop="useStatus"
                            label="使用状态">
                        <template slot-scope="scope">
                            <span v-if="scope.row.useStatus==0">未使用</span>
                            <span v-if="scope.row.useStatus==1">已使用</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                            prop="useTime"
                            label="使用时间">
                    </el-table-column>
                    <el-table-column
                            prop="orderId"
                            label="订单ID">
                    </el-table-column>
                    <el-table-column
                            prop="orderNumber"
                            label="订单编号">
                    </el-table-column>
                </el-table>

                <!--分页-->
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pageUtil.currentPage"
                        :page-sizes="[5,10,15,20]"
                        :page-size="pageUtil.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </template>
        </el-card>
    </div>
</template>

<script>
    import qs from 'qs';
    export default {
        name: "ShowCouponRecord",

        data(){
            return {
                options:[
                    {
                        value:0,
                        lable:'未使用'
                    },
                    {
                        value:1,
                        lable:'已使用'
                    }
                ],

                //条件搜索对象
                couponRecordFormData:{
                    couponName:'',
                    clientName:'',
                    useStatus:'',
                    orderNumber:''
                },

                //表格数据
                tableData:[],

                pageUtil:{
                    //每页显示的条数
                    pageSize: 5,
                    //当前的显示的页码
                    currentPage:0,
                },
                //总条数
                total:0,
            }
        },


        methods:{

            // 查询优惠券记录信息
            getAllCouponRecord() {
                this.$axios({
                    method:'post',
                    url:'clms-client/couponRecord/getAllCouponRecord',
                    params:{
                        currentPage: this.pageUtil.currentPage,
                        pageSize: this.pageUtil.pageSize
                    },
                    data:qs.stringify(this.couponRecordFormData)
                }).then(r=>{
                    this.total = r.data.object;
                    this.tableData = r.data.listData;
                    console.log(r.data.listData)
                })
            },
            // 改变每页显示的条数时触发该方法
            handleSizeChange(val){
                this.pageUtil.pageSize = val;
                this.getAllCouponRecord();
            },
            //切换页码时触发该方法
            handleCurrentChange(val){
                this.pageUtil.currentPage = val;
                this.getAllCouponRecord();
            }

        },

        // 钩子函数
        created() {
            // 查询优惠券记录信息
            this.getAllCouponRecord();
        }

    }
</script>

<style scoped>

</style>